#include "mypushbutton.h"
#include "qdebug.h"
#include "QPropertyAnimation"
//MyPushButton::MyPushButton(QWidget *parent) : QWidget(parent)
//{

//}
MyPushButton::MyPushButton(QString nomalImg,QString pressImg){
    this->nomalImgPath=nomalImg;
    this->pressImgPath=pressImg;
    QPixmap pix;
   bool ret=pix.load(nomalImg);
   if(!ret)
   {
       qDebug()<<"图片加载失败";
       return;
   }
   this->resize(pix.width(), pix.height());

       this->setStyleSheet("QPushButton{border:0px;}");

       this->setIcon(pix);

       this->setIconSize(pix.size());
}
void MyPushButton::zoom1(){
   QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
   animation->setDuration(200);
   animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
   animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
   animation->setEasingCurve(QEasingCurve::OutBounce);
   animation->start();
}
void MyPushButton::zoom2(){
    QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
    animation->setDuration(200);
    animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start();
}
//void MyPushButton::mousePressEvent(QMouseEvent *e){
//  if(this->pressImgPath != ""){
//   //        this->setStyleSheet("background: rgb(255,150,128)");
//           QPixmap pix;
//           bool res = pix.load(this->pressImgPath);
//           if(!res){
//               qDebug() << nomalImgPath << "load fail";
//               return;
//           }

//           //this->setFixedSize(pix.size());

//           this->resize(pix.width(), pix.height());

//           this->setStyleSheet("QPushButton{border:0px;}");

//           this->setIcon(pix);

//           this->setIconSize(pix.size());
//}
//    return QPushButton::mouseReleaseEvent(e);
//}
//    void MyPushButton::mouseReleaseEvent(QMouseEvent *e){
//       if(this->pressImgPath!= ""){
//        //        this->setStyleSheet("background-color: rgb(0,0,255)");
//                QPixmap pix;
//                bool res = pix.load(this->nomalImgPath);
//                if(!res){
//                    qDebug() << nomalImgPath << "load fail";
//                    return;
//                }

//                //this->setFixedSize(pix.size());

//                this->resize(pix.width(), pix.height());

//                this->setStyleSheet("QPushButton{border:0px;}");

//                this->setIcon(pix);

//                this->setIconSize(pix.size());
//    }
//        return QPushButton::mouseReleaseEvent(e);
//    }
MyPushButton::~MyPushButton(){}
